<?php

namespace app\common\validate;

class Ask extends BaseValidate{

	// 验证规则
	protected $rule = [
		'title'       => 'require',
		'category_id' => 'require',
		'reward'      => 'checkReward',
	];
	// 使用场景
	protected $scene = [
		'add'  => ['title', 'category_id', 'reward'],
		'save' => ['title', 'category_id', 'reward'],
	];
	// 提示消息设置
	protected $message = [
		'title.require'       => '标题不能为空',
		'category_id.require' => '请选择话题',
	];
	// 悬赏验证
    protected function checkReward($value, $rule, $data){
		$user_id = $data['user_id'];
		$reward  = model('UserAccount')->get_account_money($user_id, 'reward_usable');
    	if(floatval($reward) < floatval($value)){
    		return '您的豆子不足';
    	}
    	return true;
    }
}